# Bike-Share Data Preprocessing Explanation

## Introduction
The bike-share regression model predicts hourly counts of casual and registered bike rentals from historical data.  
Neural networks perform best when all input features are numeric, appropriately scaled, and free of artificial discontinuities.  
This document explains each preprocessing step in detail and the rationale behind it.

## 1. Datetime Feature Extraction
The raw `datetime` field contains both date and time information. We extract three numeric components from it:
- **Hour of day** (0–23)  
- **Day of week** (0–6, Monday=0)  
- **Month of year** (1–12)  

These values capture important periodic patterns: daily rush hours, weekday/weekend cycles, and seasonal trends.

## 2. Cyclical Encoding
Numeric values for hour, day-of-week, or month “wrap around” after their maximum. For example:
- Hour 23 and hour 0 are adjacent in time, but a raw integer encoding (23 vs. 0) suggests a large distance.
- Similarly, December (12) and January (1) are adjacent months, but raw values imply a gap.

To preserve the circular nature without discontinuities, we map each feature f with period P onto the unit circle:
```
x_sin = sin(2π × f / P)
x_cos = cos(2π × f / P)
```
Why both sine and cosine?
- **Two dimensions** are required to uniquely locate a point on the circle.  
- Using both maintains the order and distance relationships: points that are close in the cycle remain close in the transformed space.  
- The network can then learn patterns that respect the periodicity (e.g., evening and early morning hours are nearby).

## 3. One-Hot Encoding of Categorical Variables
Certain features are categorical without inherent numeric order:
- **season** (1 = spring, ..., 4 = winter)  
- **holiday** (0 = no, 1 = yes)  
- **workingday** (0 = no, 1 = yes)  
- **weather** (1 – 4 various conditions)  

If we leave these as integers, the model might assume that a higher number implies “more” or “better.”  
One-hot encoding converts each category into a separate binary feature (0 or 1), ensuring:
- No artificial ordering is introduced.  
- The network treats each category independently.

## 4. Standardizing Continuous Variables
Continuous measurements can have different ranges and distributions:
- **temp** (°C)  
- **atemp** (“feels like” °C)  
- **humidity** (%)  
- **windspeed** (km/h)  

Standardization rescales each feature to zero mean and unit variance:
```
x_std = (x − mean) / std
```
Rationale:
- Centers data around zero, which aligns with typical weight initialization at small random values.  
- Scales features uniformly, preventing those with larger numeric ranges from dominating gradient updates.  
- Empirically accelerates convergence and improves stability during training.

## 5. Feature Vector Assembly
After transformation, each sample’s final feature vector is the concatenation of:
1. **Cyclical components** (sin+cos for hour, day, month)  
2. **One-hot category flags**  
3. **Standardized continuous values**  

The neural network input layer size equals the total number of these engineered features. Proper preprocessing ensures the model can learn meaningful temporal, categorical, and numeric patterns effectively and reliably.

## 6. Evaluation Metrics

To evaluate the performance of the regression model, we use these metrics:

### Mean Squared Error (MSE)
The average of squared differences between predicted and actual values:
```
MSE = (1/n) * Σ (y_pred - y_actual)²
```
Where:
- `n` is the number of samples
- `y_pred` is the predicted rental count
- `y_actual` is the actual rental count

### Root Mean Squared Error (RMSE)
The square root of MSE, giving a measure in the same units as the target (bike rentals):
```
RMSE = √MSE
```

RMSE is particularly useful because:
- It's in the same units as the target variable (number of bike rentals)
- It represents the standard deviation of prediction errors (residuals)
- A lower RMSE indicates better model fit
- The value can be interpreted as the typical magnitude of prediction error

For example, if a model has an RMSE of 89, it means predictions are typically off by about 89 bikes. Whether this is acceptable depends on the context - if typical rental counts are in the hundreds, this might be reasonable; if they're typically less than 100, this would indicate poor model performance.